import { createRouter, createWebHashHistory } from "vue-router";

const routes = [{
        path: "/",
        redirect: "/index",
    },

    {
        path: "/login",
        component: () =>
            import ("../views/login/Index.vue"),
    },
    // 首页
    {
        path: "/index",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // index 右侧路由
        children: [{
                path: "/index/",
                redirect: "/index/child",
            },
            {
                path: "/index/child",
                component: () =>
                    import ("../views/index/components/Index"),
            },
        ],
        meta: {
            requireLogin: true,
        },
    },
    // 个人设置
    {
        path: "/index",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // index 右侧路由
        children: [{
                path: "/personal/",
                redirect: "/personal/child",
            },
            {
                path: "/personal/child",
                component: () =>
                    import ("../views/personal/components/Index"),
            },
        ],
    },
    // 用户管理
    {
        path: "/user",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/user/",
                redirect: "/user/jszh",
            },
            {
                path: "/user/jszh",
                component: () =>
                    import ("../views/usermanage/components/jszh"),
            },
            {
                path: "/user/xszh",
                component: () =>
                    import ("../views/usermanage/components/xszh"),
            },
            {
                path: "/user/kfzh",
                component: () =>
                    import ("../views/usermanage/components/kfzh"),
            },
        ],
    },
    // 教务管理
    {
        path: "/edu",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/edu/",
                redirect: "/edu/kcgl",
            },
            {
                path: "/edu/kcgl",
                component: () =>
                    import ("../views/eduservice/components/kcgl"),
            },
            {
                path: "/edu/mxjs",
                component: () =>
                    import ("../views/eduservice/components/mxjs"),
            },
            {
                path: "/edu/jskq",
                component: () =>
                    import ("../views/eduservice/components/jskq"),
            },
        ],
    },
    // 学生服务
    {
        path: "/stu",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/stu/",
                redirect: "/stu/kcjs",
            },
            {
                path: "/stu/kcjs",
                component: () =>
                    import ("../views/stuservice/components/kcjs"),
            },
            {
                path: "/stu/zxkf",
                component: () =>
                    import ("../views/stuservice/components/zxkf"),
            },
        ],
    },
    // 订单管理
    {
        path: "/order",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/order/",
                redirect: "/order/kcdd",
            },
            {
                path: "/order/kcdd",
                component: () =>
                    import ("../views/order/components/kcdd"),
            },
        ],
    },
    // 系统消息
    {
        path: "/message",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/message/",
                redirect: "/message/czrz",
            },
            {
                path: "/message/czrz",
                component: () =>
                    import ("../views/systemmsg/components/czrz"),
            },
            {
                path: "/message/xxtz",
                component: () =>
                    import ("../views/systemmsg/components/xxtz"),
            },
        ],
    },
    // 个人设置
    {
        path: "/index",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // index 右侧路由
        children: [{
                path: "/personal/",
                redirect: "/personal/child",
            },
            {
                path: "/personal/child",
                component: () =>
                    import ("../views/personal/components/Index"),
            },
        ],
    },
    // 用户管理
    {
        path: "/user",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/user/",
                redirect: "/user/jszh",
            },
            {
                path: "/user/jszh",
                component: () =>
                    import ("../views/usermanage/components/jszh"),
            },
            {
                path: "/user/xszh",
                component: () =>
                    import ("../views/usermanage/components/xszh"),
            },
            {
                path: "/user/kfzh",
                component: () =>
                    import ("../views/usermanage/components/kfzh"),
            },
        ],
    },
    // 教务管理
    {
        path: "/edu",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/edu/",
                redirect: "/edu/kcgl",
            },
            {
                path: "/edu/kcgl",
                component: () =>
                    import ("../views/eduservice/components/kcgl"),
            },
            {
                path: "/edu/mxjs",
                component: () =>
                    import ("../views/eduservice/components/mxjs"),
            },
            {
                path: "/edu/jskq",
                component: () =>
                    import ("../views/eduservice/components/jskq"),
            },
        ],
    },
    // 学生服务
    {
        path: "/stu",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/stu/",
                redirect: "/stu/kcjs",
            },
            {
                path: "/stu/kcjs",
                component: () =>
                    import ("../views/stuservice/components/kcjs"),
            },
            {
                path: "/stu/zxkf",
                component: () =>
                    import ("../views/stuservice/components/zxkf"),
            },
        ],
    },
    // 订单管理
    {
        path: "/order",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/order/",
                redirect: "/order/kcdd",
            },
            {
                path: "/order/kcdd",
                component: () =>
                    import ("../views/order/components/kcdd"),
            },
            {
                path: "/order/details/:id",
                props: true,
                component: () =>
                    import ("../views/order/components/details"),
            },
        ],
    },
    // 系统消息
    {
        path: "/message",
        component: () =>
            import ("../views/topandleft/Index.vue"),
        // user 右侧
        children: [{
                path: "/message/",
                redirect: "/message/czrz",
            },
            {
                path: "/message/czrz",
                component: () =>
                    import ("../views/systemmsg/components/czrz"),
            },
            {
                path: "/message/xxtz",
                component: () =>
                    import ("../views/systemmsg/components/xxtz"),
            },
        ],
    },
    // 404路由
    {
        path: "/:pathMatch(.*)",
        component: () =>
            import ("../views/NotFound"),
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    if (to.meta.requireLogin) {
        // 是否已经登录
        if (localStorage.getItem("token")) {
            next();
        } else {
            next("/login");
        }
    } else {
        next();
    }
});

export default router;